home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 413_01 / sndblst4 / voice.c < prev    next >
Text File  |  1993-12-10  |  8KB  |  245 lines

  1.  
  2. //------------------------------------------------------------------------------
  3. // Copyright (c) David Welch, 1993
  4. //------------------------------------------------------------------------------
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <conio.h>
  10.  
  11. #include "sb.h"
  12.  
  13. #define USHORT unsigned short
  14.  
  15. typedef struct
  16. {
  17.     char name[20];
  18.     unsigned short off;
  19.     unsigned short ver;
  20.     unsigned short id;
  21. } VOCHEADER;
  22.  
  23. char gstring[80];
  24. unsigned char ca;
  25. unsigned short ra;
  26. unsigned long la;
  27. FILE *fp;
  28.  
  29. VOCHEADER v;
  30. char dtype;
  31. unsigned long dlen;
  32. unsigned char tc;
  33. unsigned char pt;
  34. unsigned char md;
  35. unsigned char min;
  36. unsigned char max;
  37. unsigned long length;
  38.  
  39. //------------------------------------------------------------------------------
  40. void main ( int argc, char *argv[] )
  41. {
  42.     if(argc==1)
  43.     {
  44.         printf(".VOC file not specified\n");
  45.         exit(1);
  46.     }
  47.     strcpy(gstring,argv[1]);
  48.     strcat(gstring,".VOC");
  49.     if((fp=fopen(gstring,"rb"))==NULL)
  50.     {
  51.         strcpy(gstring,argv[1]);
  52.         if((fp=fopen(gstring,"rb"))==NULL)
  53.         {
  54.             printf("Error opening .VOC file [%s]\n",argv[1]);
  55.             exit(1);
  56.         }
  57.     }
  58.     printf("FILE:  [%s]\n",gstring);
  59.     sbinit();
  60.     sbmalloc();
  61.     fread(&v,1,sizeof(VOCHEADER),fp);
  62.     for(ra=0;ra<19;ra++) gstring[ra]=v.name[ra]; gstring[ra]=0;
  63.     if((strcmp(gstring,"Creative Voice File")!=0)||(v.name[ra]!=0x1A))
  64.     {
  65.         printf("Not a Creative Voice File (.VOC)\n");
  66.         exit(1);
  67.     }
  68.     printf("Creative Voice File  V%u.%02u\n",(v.ver>>8)&0xFF,v.ver&0xFF);
  69.     printf("Data starts at offset %08Xh\n",v.off);
  70.     printf("Voice file identification code %04Xh, ",v.id);
  71.     if((((~v.ver)+0x1234)&0xFFFF)==v.id) printf("passed\n");
  72.     else { printf("failed\n"); exit(1); }
  73.     while(1)
  74.     {
  75.         if(fread(&dtype,1,1,fp)==0) break;
  76.         dlen=0; fread(&dlen,1,3,fp);
  77.         printf("\nBlock Type %u:  ",(USHORT)dtype);
  78.         if(dtype==0)
  79.         {
  80.             printf("Terminator\n");
  81.             break;
  82.         }
  83.         if(dtype==1)
  84.         {
  85.             printf("Voice Data\n");
  86.             printf("Block Length %lu\n",dlen);
  87.             fread(&tc,1,1,fp);
  88.             printf("Time Constant %u, ",(USHORT)tc);
  89.             ra=1000000L/(256L-tc);
  90.             printf("%u Hz\n",ra);
  91.             fread(&pt,1,1,fp);
  92.             printf("Pack type %u:  ",(USHORT)pt);
  93.             switch(pt)
  94.             {
  95.                 case 0: printf("8 bit unpacked\n"); break;
  96.                 case 1: printf("4 bit packed\n"); break;
  97.                 case 2: printf("2.6 bit packed\n"); break;
  98.                 case 3: printf("2 bit packed\n"); break;
  99.                 case 4: printf("1 channel multi\n"); break;
  100.                 case 5: printf("2 channel multi\n"); break;
  101.                 case 6: printf("3 channel multi\n"); break;
  102.                 case 7: printf("4 channel multi\n"); break;
  103.                 case 8: printf("5 channel multi\n"); break;
  104.                 case 9: printf("6 channel multi\n"); break;
  105.                 case 10: printf("7 channel multi\n"); break;
  106.                 default: printf("Unknown\n"); break;
  107.             }
  108.             if(pt==0)
  109.             {
  110.                 sbsettc(tc);
  111.                 spkon();
  112.                 length=dlen-2;
  113.                 while(length)
  114.                 {
  115.                     if(length>65000) la=65000; else la=length;
  116.                     length-=la;
  117.                     fread(aligned,1,la,fp);
  118.                     sbplay(la);
  119.                     printf("%lu Samples\n",la);
  120. //                  while(dmacount()!=0xFFFF)
  121.                     dmastatus();
  122.                     while(!dmastatus())
  123.                     {
  124.                         if(kbhit())
  125.                         {
  126.                             sbhaltdma();
  127.                             getch();
  128.                             spkoff();
  129.                             exit(0);
  130.                         }
  131.                     }
  132.                 }
  133.                 spkoff();
  134.             }
  135.             else
  136.             {
  137.                 printf("Invalid pack type\n");
  138.                 fseek(fp,ftell(fp)+dlen-2,0);
  139.             }
  140.         }
  141.         if(dtype==2)
  142.         {
  143.             printf("Voice Continuation\n");
  144.             printf("Block Length %lu\n",dlen);
  145.             max=0x00;
  146.             min=0xFF;
  147.             for(la=0;la<dlen;la++)
  148.             {
  149.                 fread(&ca,1,1,fp);
  150.                 if(ca>max) max=ca;
  151.                 if(ca<min) min=ca;
  152.             }
  153.             printf("Maximum %u, Minimum %u\n",(USHORT)max,(USHORT)min);
  154.         }
  155.         if(dtype==3)
  156.         {
  157.             printf("Silence\n");
  158.             printf("Block Length (always 3) %lu\n",dlen);
  159.             fread(&ra,1,2,fp);
  160.             printf("Period %u\n",ra);
  161.             fread(&tc,1,1,fp);
  162.             printf("Time Constant %u, ",(USHORT)tc);
  163.             ra=1000000L/(256L-tc);
  164.             printf("%u Hz\n",ra);
  165.         }
  166.         if(dtype==4)
  167.         {
  168.             printf("Marker");
  169.             printf("Block Length %lu\n",dlen);
  170.             fread(&ra,1,2,fp);
  171.             printf("Marker value %u, %04Xh\n",ra,ra);
  172.             if(dlen>2) fseek(fp,ftell(fp)+dlen-2,0);
  173.         }
  174.         if(dtype==5)
  175.         {
  176.             printf("ASCII Text\n");
  177.             printf("Block Length %lu\n",dlen);
  178.             la=dlen;
  179.             while(la)
  180.             {
  181.                 if(la>79) ca=79; else ca=la;
  182.                 la-=ca;
  183.                 fread(gstring,1,ca,fp); gstring[79]=0;
  184.                 printf("%s",gstring);
  185.             }
  186.         }
  187.         if(dtype==6)
  188.         {
  189.             printf("Repeat Loop\n");
  190.             printf("Block Length (always 2) %lu\n",dlen);
  191.             fread(&ra,1,2,fp);
  192.             printf("Count %u\n",ra);
  193.         }
  194.         if(dtype==7)
  195.         {
  196.             printf("End Repeat Loop\n");
  197.             printf("Block Length (always 0) %lu\n",dlen);
  198.         }
  199.         if(dtype==8)
  200.         {
  201.             printf("Extended Block\n");
  202.             printf("Block Length (always 4) %lu\n",dlen);
  203.             fread(&ra,1,2,fp);
  204.             printf("Time constant %u, ",ra);
  205.             ra=256000000L/(65536L-ra);
  206.             printf("%u Hz\n",ra);
  207.             fread(&pt,1,1,fp);
  208.             printf("Pack type %u:  ",(USHORT)pt);
  209.             switch(pt)
  210.             {
  211.                 case 0: printf("8 bit unpacked\n"); break;
  212.                 case 1: printf("4 bit packed\n"); break;
  213.                 case 2: printf("2.6 bit packed\n"); break;
  214.                 case 3: printf("2 bit packed\n"); break;
  215.                 case 4: printf("1 channel multi\n"); break;
  216.                 case 5: printf("2 channel multi\n"); break;
  217.                 case 6: printf("3 channel multi\n"); break;
  218.                 case 7: printf("4 channel multi\n"); break;
  219.                 case 8: printf("5 channel multi\n"); break;
  220.                 case 9: printf("6 channel multi\n"); break;
  221.                 case 10: printf("7 channel multi\n"); break;
  222.                 default: printf("Unknown\n"); break;
  223.             }
  224.             fread(&md,1,1,fp);
  225.             printf("Mode %u, ",(USHORT)md);
  226.             switch(md)
  227.             {
  228.                 case 0: printf("mono\n"); break;
  229.                 case 1: printf("stereo\n"); break;
  230.                 default: printf("unknown\n"); break;
  231.             }
  232.         }
  233.         if(dtype>8)
  234.         {
  235.             printf("UNKNOWN\n");
  236.             printf("Block Length %lu\n",dlen);
  237.             fseek(fp,ftell(fp)+dlen,0);
  238.         }
  239.     }
  240. }
  241. //------------------------------------------------------------------------------
  242. // Copyright (c) David Welch, 1993
  243. //------------------------------------------------------------------------------
  244.  
  245.